/************************************************************************************\
This source file is part of the Universal Actor Library                              *
For latest info, see http://libuniactor.sourceforge.net/                             *
**************************************************************************************
Copyright (c) 2010 Kresimir Spes (kreso@cateia.com)                                  *
*                                                                                    *
* This program is free software; you can redistribute it and/or modify it under      *
* the terms of the BSD license: http://www.opensource.org/licenses/bsd-license.php   *
\************************************************************************************/
#ifndef _Jobs_h
#define _Jobs_h

#include "UniActorExport.h"
#include "Actor.h"
#include <list>
#include <hltypes/hstring.h>

namespace UniActor
{
	class UniActorExport Job
	{
	protected:
		Actor* mActor;
		bool mStarted;
	public:
		Job();
		virtual ~Job();
		
		//! make a copy of this job, a C++ like virtual copy constructor
		virtual Job* clone()=0;
		
		void setOwner(Actor* actor);
		
		virtual void update(float time_increase)=0;
		virtual bool isDone()=0;
		virtual const hstr getTypeName()=0;
		virtual void start()=0;
		virtual void cancel();
		//! if more time has been given tu the update function, compensate by
		//! giving more time to the next job.
		virtual float calcOvertime();
		bool isExecuting() { return mStarted; }
	};

	namespace Jobs
	{
		class UniActorExport Move : public Job
		{
		protected:
			std::list<gtypes::Vector3> mWaypoints;
			gtypes::Vector3 mStartPos;
			float mDistanceTraveled,mDistanceToTravel;
			
			void updateToNextWaypoint();
		public:
			Move();
			Move(float dx,float dy,float dz);
			Move(Move& m);
			~Move();
			
			Job* clone();
			void start();
			void update(float time_increase);
			bool isDone();
			const hstr getTypeName() { return "Move"; }
		};
		
		class UniActorExport Animate : public Job
		{
			hstr mAnimationName;
			float mAnimationTime;
			float mTimer;
			bool mLoop;
		public:
			Animate();
			Animate(chstr ani_name,bool loop=0);
			Animate(Animate& m);
			~Animate();
			
			Job* clone();
			void start();
			void update(float time_increase);
			bool isDone();
			const hstr getTypeName() { return "Animate"; }
		};
	}
}
#endif
